package com.atguigu.spring.methodOverrides.lookup;


import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
public class LookupConfig {

	@Bean
	@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
	public Apple apple() {
		return new Apple();
	}

	@Bean
	@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
	public Banana banana() {
		return new Banana();
	}

	@Bean
	public FruitPlate fruitPlate1(ObjectProvider<Apple> apple) {
		return new FruitPlate() {
			@Override
			public Fruit getFruit() {
				return apple.getIfAvailable();
			}
		};
	}

	@Bean
	public FruitPlate fruitPlate2() {
		return new FruitPlate() {
			@Override
//			@Lookup
			public Fruit getFruit() {
				return banana();
			}
		};
	}

}
